package com.uplooking.util;

import java.util.List;

public class PagerUtils {

	private int index;

	private int size;

	private long count;

	private int page;

	private int step;

	private int begin;

	private int end;

	private List<?> items;

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public long getCount() {
		return count;
	}

	public void setCount(long count) {
		this.count = count;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getStep() {
		return step;
	}

	public void setStep(int step) {
		this.step = step;
	}

	public int getBegin() {
		return begin;
	}

	public void setBegin(int begin) {
		this.begin = begin;
	}

	public int getEnd() {
		return end;
	}

	public void setEnd(int end) {
		this.end = end;
	}

	public List<?> getItems() {
		return items;
	}

	public void setItems(List<?> items) {
		this.items = items;
	}

	public PagerUtils() {
		super();
	}

	public PagerUtils(int index, int size, long count, int step) {
		super();
		this.index = index;
		this.size = size;
		this.count = count;
		this.step = step;
		if (this.count == 0) {
			this.index = 1;
			this.begin = 1;
			this.end = 1;
		} else {
			this.page = (int) (count % size == 0 ? count / size : count / size + 1);
			if (this.index > this.page)
				this.index = this.page;
			if (this.index < 1)
				this.index = 1;
			this.begin = ((this.index - 1) / this.step) * this.step + 1;
			this.end = ((this.index - 1) / this.step + 1) * this.step;
			if (this.end > this.page)
				this.end = this.page;
		}
	}

	@Override
	public String toString() {
		return "PagerUtils [index=" + index + ", size=" + size + ", count=" + count + ", page=" + page + ", step="
				+ step + ", begin=" + begin + ", end=" + end + ", items=" + items + "]";
	}
}
